#include <stdio.h>
int main()
{
  int i,n,sum=0;
  scanf("%d",&n);
  while(n>=3){
    i=0;
    i=n%3;
    n/=3;
    sum+=n*3;
    n+=i;
    printf("%d\n%d\n%d\n",n,i,sum);
  }
  sum+=n;
  printf("%d",sum);
  return 0;
}
